package com.maxwell.googleplay.fragment;

import java.util.List;
import java.util.Random;

import com.maxwell.googleplay.adapter.AppItemAdapter;
import com.maxwell.googleplay.base.BaseFragment;
import com.maxwell.googleplay.base.LoadingPager.LoadedResult;
import com.maxwell.googleplay.base.SuperBaseAdapter;
import com.maxwell.googleplay.bean.AppInfoBean;
import com.maxwell.googleplay.factory.ListViewFactory;
import com.maxwell.googleplay.holder.AppItemHolder;
import com.maxwell.googleplay.holder.BaseHolder;
import com.maxwell.googleplay.protocol.GameProtocol;
import com.maxwell.googleplay.utils.UIUtils;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ListView;
import android.widget.TextView;

/**
 * @author yue
 * @创建时间 2016-3-30上午9:26:27
 * @描述 TODO
 * 
 */
public class GameFragment extends BaseFragment {
	private List<AppInfoBean> mDatas;
	private GameProtocol mProtocol;

	@Override
	public LoadedResult initData() {
		mProtocol = new GameProtocol();
		try {
			mDatas = mProtocol.loadData(0);
			return checkState(mDatas);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return LoadedResult.ERROR;
		}

	}

	@Override
	public View initSuccessView() {
		ListView listView = ListViewFactory.createListView();
		//设置适配器
		listView.setAdapter(new GameAdapter(listView, mDatas));

		return listView;
	}
	
	class GameAdapter extends AppItemAdapter{

		public GameAdapter(AbsListView absListView, List<AppInfoBean> dataSource) {
			super(absListView, dataSource);
			// TODO Auto-generated constructor stub
		}

		@Override
		public List<AppInfoBean> onLoadMore() throws Exception {
			// TODO Auto-generated method stub
			return mProtocol.loadData(mDatas.size());
		}
		
	}
	
}
